"""
    
    Thread utilities.

"""

__author__ = "Mikko Ohtamaa <mikko@redinnovation.com"
__docformat__ = "epytext"
__copyright__ = "Red Innovation Ltd."
__license__ = "BSD"


class TimeoutLock:
    """ A lock which will be forced to open after certain timeout. 
    
    This class uses human-readable messages to make multi-thread 
    logging and debugging more comfortable.
    """
    
    def __init__(self, name):
        """
        
        @param name: Log visible name of the lock
        """
        #: Reason for signaling() the lock or None
        self.signal_reason = None
        self.name = name
        
    def reset(self):        
        """ Clear all pending signals. 
        
        This restores the lock to its pristine state.        
        """
        self.signal_reason = None
                
    def signal(self, reason = "signal() called"):
        """ Call this from other thread to open the lock.
        
        If signal() is called before wait(), wait() won't wait.
        
        
        @param reason: Log visible message why the lock was opened
        @type reason: string        
        """
        raise NotImplementedError()                        
    
    def trigger_timeout(self):
        #self.timer = None
        self.signal("timeout triggered")
        
    def get_signal_reason(self):
        return self.signal_reason
        
    def wait(self, timeout):        
        raise NotImplementedError()                            

class Thread:
    pass

class Timer:
    pass